#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Zhangcl
# from db import  connect_db
from db.connect_db import engine,Students,Teacher,Classes,Class_choise,Class_record,Homework,Grade,Admin
from sqlalchemy.orm import sessionmaker
session_connet = sessionmaker(bind=engine)
session = session_connet()

class User_login(object):
    def __init__(self,login_user,login_passwd,user_type):
        self.login_user= login_user
        self.login_passwd= login_passwd
        self.user_type = user_type
    def type_choise(self):
        if self.user_type == 'students':
            obj =session.query(Students).filter(Students.qq==self.login_user).first()
            run='students'

        if self.user_type == 'teacher':
            obj = session.query(Teacher).filter(Teacher.name == self.login_user).first()
            run= 'teacher'

        if self.user_type == 'admin':
            obj = session.query(Admin).filter(Admin.name == self.login_user).first()
            run= 'admin'

        if obj is None: #如果返回空说明没有对应的账户
            print('该用户名不存在！')
        else:
            if obj.passwd == self.login_passwd:#账户存在即验证密码
                return run #验证通过把对应的账户类型返回
            else:
                print('密码错误！')
                return False
